<template>
  <div id="app" class="app">
    <topbar v-show="isShowTop" class="topbar" :path="path"></topbar>
    <router-view v-slot="{ Component }">
      <component :is="Component" />
    </router-view>
    <div class="aplayer" v-if="musicInfoArr[0]">
      <aplayer
        autoplay = true
        showLrc
        :music="{
          title: musicInfoArr[0].name,
          artist: musicInfoArr[0].ar[0].name,
          pic: musicInfoArr[0].al.picUrl,
          src:musicInfoArr[0].url,
          lrc: musicInfoArr[0].lyric
        }"
      />
    </div>
    <navbar class="navbar"></navbar>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, computed } from "vue";
import { useRoute } from "vue-router";
import Navbar from "@/components/Navbar/index.vue";
import Topbar from "@/components/Topbar/index.vue";
import Aplayer from "vue3-aplayer";
import { useStore } from "vuex";

export default defineComponent({
  name: "App",
  components: {
    Navbar,
    Topbar,
    Aplayer,
  },
  setup() {
    const store = useStore();
    const musicInfoArr = store.state.music;
    const route = useRoute();
    const path = ref("");
    const isShowTop = computed(() => {
      if (route.path === "/discover") {
        return true;
      } else {
        return false;
      }
    });

    return {
      path,
      isShowTop,
      musicInfoArr
    };
  },
});
</script>

<style>
@import url("./assets/styles/base.css");
@import url("./assets/styles/global.css");
@import url("./assets/styles/normalize.css");

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.topbar {
  position: fixed;
  z-index: 9999;
  top: 0;
  left: 0;
  right: 0;
}

.navbar {
  position: fixed;
  z-index: 9999;
  bottom: 0;
  left: 0;
  right: 0;
}

.toggle-enter-active {
  transition: all 0.3s;
}

.toggle-leave-active {
  transition: all 0.8s;
}

.toggle-enter-from,
.toggle-leave-to {
  transform: translateY(100vh);
}
.aplayer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 100rem;
}
</style>